home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 92 / CDMM92_1.ISO / SOF 2 SDK / sof2sdk-101.msi / _92D6AC311BB48EBA344BBABC89DA6AB0 / _320DB8F688F4419A9D80133EE151683B < prev    next >
Encoding:
Text File  |  2002-07-11  |  47.3 KB  |  1,792 lines

  1. // Copyright (C) 2001-2002 Raven Software.
  2. //
  3. #ifndef __Q_SHARED_H
  4. #define __Q_SHARED_H
  5.  
  6. // q_shared.h -- included first by ALL program modules.
  7. // A user mod should never modify this file
  8.  
  9. #ifdef GERMAN_BUILD
  10.     #define    Q3_VERSION        "SOF2MP V1.01g"        // sent on 6/10/2002
  11.     #define SOF2_VERSION_ID    "1.01g"                // sent on 6/10/2002
  12. #else
  13.     #define    Q3_VERSION        "SOF2MP V1.01"        // sent on 6/10/2002
  14.     #define SOF2_VERSION_ID    "1.01"                // sent on 6/10/2002
  15. #endif
  16.  
  17. //#define SPECIAL_PRE_CACHE    1
  18.  
  19. #ifdef _DEBUG
  20. #define _SOF2_BOTS
  21. #endif
  22.  
  23. #define MAX_TEAMNAME 32
  24.  
  25. #include "../qcommon/disablewarnings.h"
  26.  
  27. /**********************************************************************
  28.   VM Considerations
  29.  
  30.   The VM can not use the standard system headers because we aren't really
  31.   using the compiler they were meant for.  We use bg_lib.h which contains
  32.   prototypes for the functions we define for our own use in bg_lib.c.
  33.  
  34.   When writing mods, please add needed headers HERE, do not start including
  35.   stuff like <stdio.h> in the various .c files that make up each of the VMs
  36.   since you will be including system headers files can will have issues.
  37.  
  38.   Remember, if you use a C library function that is not defined in bg_lib.c,
  39.   you will have to add your own version for support in the VM.
  40.  
  41.  **********************************************************************/
  42.  
  43. #ifdef Q3_VM
  44.  
  45. #include "bg_lib.h"
  46.  
  47. #define assert(exp)     ((void)0)
  48.  
  49. #define min(x,y) ((x)<(y)?(x):(y))
  50. #define max(x,y) ((x)>(y)?(x):(y))
  51.  
  52. #else
  53.  
  54. #include <assert.h>
  55. #include <math.h>
  56. #include <stdio.h>
  57. #include <stdarg.h>
  58. #include <string.h>
  59. #include <stdlib.h>
  60. #include <time.h>
  61. #include <ctype.h>
  62. #include <limits.h>
  63.  
  64. #endif
  65.  
  66. #ifdef _WIN32
  67.  
  68. //#pragma intrinsic( memset, memcpy )
  69.  
  70. #endif
  71.  
  72. #define EFFECT_SMOKE 0
  73. #define EFFECT_EXPLOSION 1
  74. #define EFFECT_SPARK_EXPLOSION 2
  75.  
  76. // this is the define for determining if we have an asm version of a C function
  77. #if (defined _M_IX86 || defined __i386__) && !defined __sun__  && !defined __LCC__
  78. #define id386    1
  79. #else
  80. #define id386    0
  81. #endif
  82.  
  83. #if (defined(powerc) || defined(powerpc) || defined(ppc) || defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY)
  84. #define idppc    1
  85. #else
  86. #define idppc    0
  87. #endif
  88.  
  89. // for windows fastcall option
  90.  
  91. #define    QDECL
  92.  
  93. short   ShortSwap (short l);
  94. int        LongSwap (int l);
  95. float    FloatSwap (const float *f);
  96.  
  97. //======================= WIN32 DEFINES =================================
  98.  
  99. #ifdef WIN32
  100.  
  101. #define    MAC_STATIC
  102.  
  103. #undef QDECL
  104. #define    QDECL    __cdecl
  105.  
  106. // buildstring will be incorporated into the version string
  107. #ifdef NDEBUG
  108. #ifdef _M_IX86
  109. #define    CPUSTRING    "win-x86"
  110. #elif defined _M_ALPHA
  111. #define    CPUSTRING    "win-AXP"
  112. #endif
  113. #else
  114. #ifdef _M_IX86
  115. #define    CPUSTRING    "win-x86-debug"
  116. #elif defined _M_ALPHA
  117. #define    CPUSTRING    "win-AXP-debug"
  118. #endif
  119. #endif
  120.  
  121. #define ID_INLINE __inline 
  122.  
  123. static ID_INLINE short BigShort( short l) { return ShortSwap(l); }
  124. #define LittleShort
  125. static ID_INLINE int BigLong(int l) { return LongSwap(l); }
  126. #define LittleLong
  127. static ID_INLINE float BigFloat(const float *l) { FloatSwap(l); }
  128. #define LittleFloat
  129.  
  130. #define    PATH_SEP '\\'
  131.  
  132. #endif
  133.  
  134. //======================= MAC OS X DEFINES =====================
  135.  
  136. #if defined(MACOS_X)
  137.  
  138. #define MAC_STATIC
  139. #define __cdecl
  140. #define __declspec(x)
  141. #define stricmp strcasecmp
  142. #define ID_INLINE inline 
  143.  
  144. #ifdef __ppc__
  145. #define CPUSTRING    "MacOSX-ppc"
  146. #elif defined __i386__
  147. #define CPUSTRING    "MacOSX-i386"
  148. #else
  149. #define CPUSTRING    "MacOSX-other"
  150. #endif
  151.  
  152. #define    PATH_SEP    '/'
  153.  
  154. #define __rlwimi(out, in, shift, maskBegin, maskEnd) asm("rlwimi %0,%1,%2,%3,%4" : "=r" (out) : "r" (in), "i" (shift), "i" (maskBegin), "i" (maskEnd))
  155. #define __dcbt(addr, offset) asm("dcbt %0,%1" : : "b" (addr), "r" (offset))
  156.  
  157. static inline unsigned int __lwbrx(register void *addr, register int offset) {
  158.     register unsigned int word;
  159.     
  160.     asm("lwbrx %0,%2,%1" : "=r" (word) : "r" (addr), "b" (offset));
  161.     return word;
  162. }
  163.  
  164. static inline unsigned short __lhbrx(register void *addr, register int offset) {
  165.     register unsigned short halfword;
  166.     
  167.     asm("lhbrx %0,%2,%1" : "=r" (halfword) : "r" (addr), "b" (offset));
  168.     return halfword;
  169. }
  170.  
  171. static inline float __fctiw(register float f) {
  172.     register float fi;
  173.     
  174.     asm("fctiw %0,%1" : "=f" (fi) : "f" (f));
  175.  
  176.     return fi;
  177. }
  178.  
  179. #define BigShort
  180. static inline short LittleShort(short l) { return ShortSwap(l); }
  181. #define BigLong
  182. static inline int LittleLong (int l) { return LongSwap(l); }
  183. #define BigFloat
  184. static inline float LittleFloat (const float l) { return FloatSwap(&l); }
  185.  
  186. #endif
  187.  
  188. //======================= MAC DEFINES =================================
  189.  
  190. #ifdef __MACOS__
  191.  
  192. #include <MacTypes.h>
  193. #define    MAC_STATIC
  194. #define ID_INLINE inline 
  195.  
  196. #define    CPUSTRING    "MacOS-PPC"
  197.  
  198. #define    PATH_SEP ':'
  199.  
  200. void Sys_PumpEvents( void );
  201.  
  202. #define BigShort
  203. static inline short LittleShort(short l) { return ShortSwap(l); }
  204. #define BigLong
  205. static inline int LittleLong (int l) { return LongSwap(l); }
  206. #define BigFloat
  207. static inline float LittleFloat (const float l) { return FloatSwap(&l); }
  208.  
  209. #endif
  210.  
  211. //======================= LINUX DEFINES =================================
  212.  
  213. // the mac compiler can't handle >32k of locals, so we
  214. // just waste space and make big arrays static...
  215. #ifdef __linux__
  216.  
  217. // bk001205 - from Makefile
  218. #define stricmp strcasecmp
  219.  
  220. #define    MAC_STATIC // bk: FIXME
  221. #define ID_INLINE inline 
  222.  
  223. #ifdef __i386__
  224. #define    CPUSTRING    "linux-i386"
  225. #elif defined __axp__
  226. #define    CPUSTRING    "linux-alpha"
  227. #else
  228. #define    CPUSTRING    "linux-other"
  229. #endif
  230.  
  231. #define    PATH_SEP '/'
  232.  
  233. // bk001205 - try
  234. #ifdef Q3_STATIC
  235. #define    GAME_HARD_LINKED
  236. #define    CGAME_HARD_LINKED
  237. #define    UI_HARD_LINKED
  238. #define    BOTLIB_HARD_LINKED
  239. #endif
  240.  
  241. #if !idppc
  242. inline static short BigShort( short l) { return ShortSwap(l); }
  243. #define LittleShort
  244. inline static int BigLong(int l) { return LongSwap(l); }
  245. #define LittleLong
  246. inline static float BigFloat(const float *l) { return FloatSwap(l); }
  247. #define LittleFloat
  248. #else
  249. #define BigShort
  250. inline static short LittleShort(short l) { return ShortSwap(l); }
  251. #define BigLong
  252. inline static int LittleLong (int l) { return LongSwap(l); }
  253. #define BigFloat
  254. inline static float LittleFloat (const float *l) { return FloatSwap(l); }
  255. #endif
  256.  
  257. #endif
  258.  
  259. //======================= FreeBSD DEFINES =====================
  260. #ifdef __FreeBSD__ // rb010123
  261.  
  262. #define stricmp strcasecmp
  263.  
  264. #define MAC_STATIC
  265. #define ID_INLINE inline 
  266.  
  267. #ifdef __i386__
  268. #define CPUSTRING       "freebsd-i386"
  269. #elif defined __axp__
  270. #define CPUSTRING       "freebsd-alpha"
  271. #else
  272. #define CPUSTRING       "freebsd-other"
  273. #endif
  274.  
  275. #define    PATH_SEP '/'
  276.  
  277. // bk010116 - omitted Q3STATIC (see Linux above), broken target
  278.  
  279. #if !idppc
  280. static short BigShort( short l) { return ShortSwap(l); }
  281. #define LittleShort
  282. static int BigLong(int l) { LongSwap(l); }
  283. #define LittleLong
  284. static float BigFloat(const float *l) { FloatSwap(l); }
  285. #define LittleFloat
  286. #else
  287. #define BigShort
  288. static short LittleShort(short l) { return ShortSwap(l); }
  289. #define BigLong
  290. static int LittleLong (int l) { return LongSwap(l); }
  291. #define BigFloat
  292. static float LittleFloat (const float *l) { return FloatSwap(l); }
  293. #endif
  294.  
  295. #endif
  296.  
  297. //=============================================================
  298.  
  299. typedef unsigned char         byte;
  300. typedef unsigned short        word;
  301. typedef unsigned long        ulong;
  302.  
  303. typedef enum {qfalse, qtrue}    qboolean;
  304.  
  305. typedef int        qhandle_t;
  306. typedef int        thandle_t;
  307. typedef int        fxHandle_t;
  308. typedef int        sfxHandle_t;
  309. typedef int        fileHandle_t;
  310. typedef int        clipHandle_t;
  311.  
  312.  
  313. #ifndef NULL
  314. #define NULL ((void *)0)
  315. #endif
  316.  
  317. #define    MAX_QINT            0x7fffffff
  318. #define    MIN_QINT            (-MAX_QINT-1)
  319.  
  320.  
  321. // angle indexes
  322. #define    PITCH                0        // up / down
  323. #define    YAW                    1        // left / right
  324. #define    ROLL                2        // fall over
  325.  
  326. // the game guarantees that no string from the network will ever
  327. // exceed MAX_STRING_CHARS
  328. #define    MAX_STRING_CHARS    1024    // max length of a string passed to Cmd_TokenizeString
  329. #define    MAX_STRING_TOKENS    1024    // max tokens resulting from Cmd_TokenizeString
  330. #define    MAX_TOKEN_CHARS        1024    // max length of an individual token
  331.  
  332. #define    MAX_INFO_STRING        1024
  333. #define    MAX_INFO_KEY        1024
  334. #define    MAX_INFO_VALUE        1024
  335.  
  336. #define    BIG_INFO_STRING        8192  // used for system info key only
  337. #define    BIG_INFO_KEY          8192
  338. #define    BIG_INFO_VALUE        8192
  339.  
  340.  
  341. #define    MAX_QPATH            64        // max length of a quake game pathname
  342. #ifdef PATH_MAX
  343. #define MAX_OSPATH            PATH_MAX
  344. #else
  345. #define    MAX_OSPATH            256        // max length of a filesystem pathname
  346. #endif
  347.  
  348. #define    MAX_NAME_LENGTH        32        // max length of a client name
  349.  
  350. #define    MAX_SAY_TEXT    150
  351.  
  352. // paramters for command buffer stuffing
  353. typedef enum {
  354.     EXEC_NOW,            // don't return until completed, a VM should NEVER use this,
  355.                         // because some commands might cause the VM to be unloaded...
  356.     EXEC_INSERT,        // insert at current position, but don't run yet
  357.     EXEC_APPEND            // add to end of the command buffer (normal case)
  358. } cbufExec_t;
  359.  
  360.  
  361. //
  362. // these aren't needed by any of the VMs.  put in another header?
  363. //
  364. #define    MAX_MAP_AREA_BYTES        32        // bit vector of area visibility
  365.  
  366.  
  367. #define LS_STYLES_START            0
  368. #define LS_NUM_STYLES            32
  369. #define    LS_SWITCH_START            (LS_STYLES_START+LS_NUM_STYLES)
  370. #define LS_NUM_SWITCH            32
  371. #define MAX_LIGHT_STYLES        64
  372.  
  373. // print levels from renderer (FIXME: set up for game / cgame?)
  374. typedef enum {
  375.     PRINT_ALL,
  376.     PRINT_DEVELOPER,        // only print when "developer 1"
  377.     PRINT_WARNING,
  378.     PRINT_ERROR
  379. } printParm_t;
  380.  
  381.  
  382. #ifdef ERR_FATAL
  383. #undef ERR_FATAL            // this is be defined in malloc.h
  384. #endif
  385.  
  386. // parameters to the main Error routine
  387. typedef enum {
  388.     ERR_FATAL,                    // exit the entire game with a popup window
  389.     ERR_DROP,                    // print to console and disconnect from game
  390.     ERR_SERVERDISCONNECT,        // don't kill server
  391.     ERR_DISCONNECT,                // client disconnected from the server
  392.     ERR_NEED_CD                    // pop up the need-cd dialog
  393. } errorParm_t;
  394.  
  395.  
  396. // font rendering values used by ui and cgame
  397.  
  398. #define PROP_GAP_WIDTH            3
  399. #define PROP_SPACE_WIDTH        8
  400. #define PROP_HEIGHT                27
  401. #define PROP_SMALL_SIZE_SCALE    0.75
  402.  
  403. #define BLINK_DIVISOR            200
  404. #define PULSE_DIVISOR            75
  405.  
  406. #define UI_LEFT            0x00000000    // default
  407. #define UI_CENTER        0x00000001
  408. #define UI_RIGHT        0x00000002
  409. #define UI_FORMATMASK    0x00000007
  410. #define UI_DROPSHADOW    0x00000800
  411. #define UI_BLINK        0x00001000
  412. #define UI_INVERSE        0x00002000
  413. #define UI_PULSE        0x00004000
  414.  
  415.  
  416. // Draw text defines
  417. #define DT_FORCECOLOR    0x00000001
  418. #define DT_OUTLINE        0x00000002
  419. #define DT_DROPSHADOW    0x00000004
  420.  
  421. #if defined(_DEBUG) && !defined(BSPC)
  422.     #define HUNK_DEBUG
  423. #endif
  424.  
  425. typedef enum {
  426.     h_high,
  427.     h_low,
  428.     h_dontcare
  429. } ha_pref;
  430.  
  431. #ifdef HUNK_DEBUG
  432. #define Hunk_Alloc( size, preference )                Hunk_AllocDebug(size, preference, #size, __FILE__, __LINE__)
  433. void *Hunk_AllocDebug( int size, ha_pref preference, char *label, char *file, int line );
  434. #else
  435. void *Hunk_Alloc( int size, ha_pref preference );
  436. #endif
  437.  
  438. void Com_Memset (void* dest, const int val, const size_t count);
  439. void Com_Memcpy (void* dest, const void* src, const size_t count);
  440.  
  441. #define CIN_system    1
  442. #define CIN_loop    2
  443. #define    CIN_hold    4
  444. #define CIN_silent    8
  445. #define CIN_shader    16
  446.  
  447. /*
  448. ==============================================================
  449.  
  450. MATHLIB
  451.  
  452. ==============================================================
  453. */
  454.  
  455.  
  456. typedef float vec_t;
  457. typedef vec_t vec2_t[2];
  458. typedef vec_t vec3_t[3];
  459. typedef vec_t vec4_t[4];
  460. typedef vec_t vec5_t[5];
  461.  
  462. typedef vec3_t    vec3pair_t[2];
  463.  
  464. typedef int ivec3_t[3];
  465. typedef int ivec4_t[4];
  466. typedef int ivec5_t[5];
  467.  
  468. typedef    int    fixed4_t;
  469. typedef    int    fixed8_t;
  470. typedef    int    fixed16_t;
  471.  
  472. #ifndef M_PI
  473. #define M_PI        3.14159265358979323846f    // matches value in gcc v2 math.h
  474. #endif
  475.  
  476. #define SQRT3        1.732050808f
  477.  
  478. #define NUMVERTEXNORMALS    162
  479. extern    vec3_t    bytedirs[NUMVERTEXNORMALS];
  480.  
  481. // all drawing is done to a 640*480 virtual screen size
  482. // and will be automatically scaled to the real resolution
  483. #define    SCREEN_WIDTH        640
  484. #define    SCREEN_HEIGHT        480
  485.  
  486. #define TINYCHAR_WIDTH        (SMALLCHAR_WIDTH)
  487. #define TINYCHAR_HEIGHT        (SMALLCHAR_HEIGHT/2)
  488.  
  489. #define SMALLCHAR_WIDTH        8
  490. #define SMALLCHAR_HEIGHT    16
  491.  
  492. #define BIGCHAR_WIDTH        12    // 16
  493. #define BIGCHAR_HEIGHT        13  // 16
  494.  
  495. #define    GIANTCHAR_WIDTH        32
  496. #define    GIANTCHAR_HEIGHT    48
  497.  
  498. typedef enum
  499. {
  500. CT_NONE,
  501. CT_BLACK,
  502. CT_RED,
  503. CT_GREEN,
  504. CT_BLUE,
  505. CT_YELLOW,
  506. CT_MAGENTA,
  507. CT_CYAN,
  508. CT_WHITE,
  509. CT_LTGREY,
  510. CT_MDGREY,
  511. CT_DKGREY,
  512. CT_DKGREY2,
  513.  
  514. CT_VLTORANGE,
  515. CT_LTORANGE,
  516. CT_DKORANGE,
  517. CT_VDKORANGE,
  518.  
  519. CT_VLTBLUE1,
  520. CT_LTBLUE1,
  521. CT_DKBLUE1,
  522. CT_VDKBLUE1,
  523.  
  524. CT_VLTBLUE2,
  525. CT_LTBLUE2,
  526. CT_DKBLUE2,
  527. CT_VDKBLUE2,
  528.  
  529. CT_VLTBROWN1,
  530. CT_LTBROWN1,
  531. CT_DKBROWN1,
  532. CT_VDKBROWN1,
  533.  
  534. CT_VLTGOLD1,
  535. CT_LTGOLD1,
  536. CT_DKGOLD1,
  537. CT_VDKGOLD1,
  538.  
  539. CT_VLTPURPLE1,
  540. CT_LTPURPLE1,
  541. CT_DKPURPLE1,
  542. CT_VDKPURPLE1,
  543.  
  544. CT_VLTPURPLE2,
  545. CT_LTPURPLE2,
  546. CT_DKPURPLE2,
  547. CT_VDKPURPLE2,
  548.  
  549. CT_VLTPURPLE3,
  550. CT_LTPURPLE3,
  551. CT_DKPURPLE3,
  552. CT_VDKPURPLE3,
  553.  
  554. CT_VLTRED1,
  555. CT_LTRED1,
  556. CT_DKRED1,
  557. CT_VDKRED1,
  558. CT_VDKRED,
  559. CT_DKRED,
  560.  
  561. CT_VLTAQUA,
  562. CT_LTAQUA,
  563. CT_DKAQUA,
  564. CT_VDKAQUA,
  565.  
  566. CT_LTPINK,
  567. CT_DKPINK,
  568. CT_LTCYAN,
  569. CT_DKCYAN,
  570. CT_LTBLUE3,
  571. CT_BLUE3,
  572. CT_DKBLUE3,
  573.  
  574. CT_MAX
  575. } ct_table_t;
  576.  
  577. extern vec4_t colorTable[CT_MAX];
  578.  
  579. extern    vec4_t        colorBlack;
  580. extern    vec4_t        colorRed;
  581. extern    vec4_t        colorGreen;
  582. extern    vec4_t        colorBlue;
  583. extern    vec4_t        colorYellow;
  584. extern    vec4_t        colorMagenta;
  585. extern    vec4_t        colorCyan;
  586. extern    vec4_t        colorWhite;
  587. extern    vec4_t        colorLtGrey;
  588. extern    vec4_t        colorMdGrey;
  589. extern    vec4_t        colorDkGrey;
  590. extern    vec4_t        colorLtBlue;
  591. extern    vec4_t        colorDkBlue;
  592.  
  593. #define Q_COLOR_ESCAPE    '^'
  594. #define Q_IsColorString(p)    ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) != Q_COLOR_ESCAPE )
  595.  
  596. #define COLOR_BLACK        '0'
  597. #define COLOR_RED        '1'
  598. #define COLOR_GREEN        '2'
  599. #define COLOR_YELLOW    '3'
  600. #define COLOR_BLUE        '4'
  601. #define COLOR_CYAN        '5'
  602. #define COLOR_MAGENTA    '6'
  603. #define COLOR_WHITE        '7'
  604. #define ColorIndex(c)    ( ( (c) - '0' ) & 7 )
  605.  
  606. #define S_COLOR_BLACK    "^0"
  607. #define S_COLOR_RED        "^1"
  608. #define S_COLOR_GREEN    "^2"
  609. #define S_COLOR_YELLOW    "^3"
  610. #define S_COLOR_BLUE    "^4"
  611. #define S_COLOR_CYAN    "^5"
  612. #define S_COLOR_MAGENTA    "^6"
  613. #define S_COLOR_WHITE    "^7"
  614.  
  615. extern vec4_t    g_color_table[8];
  616.  
  617. #define    MAKERGB( v, r, g, b ) v[0]=r;v[1]=g;v[2]=b
  618. #define    MAKERGBA( v, r, g, b, a ) v[0]=r;v[1]=g;v[2]=b;v[3]=a
  619.  
  620. #define DEG2RAD( a ) ( ( (a) * M_PI ) / 180.0F )
  621. #define RAD2DEG( a ) ( ( (a) * 180.0f ) / M_PI )
  622.  
  623. struct cplane_s;
  624.  
  625. extern    vec3_t    vec3_origin;
  626. extern    vec3_t    vec3_identity;
  627. extern    vec3_t    axisDefault[3];
  628.  
  629. #define    nanmask (255<<23)
  630.  
  631. #define    IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
  632.  
  633. #if idppc
  634.  
  635. static inline float Q_rsqrt( float number ) {
  636.         float x = 0.5f * number;
  637.                 float y;
  638. #ifdef __GNUC__            
  639.                 asm("frsqrte %0,%1" : "=f" (y) : "f" (number));
  640. #else
  641.         y = __frsqrte( number );
  642. #endif
  643.         return y * (1.5f - (x * y * y));
  644.     }
  645.  
  646. #ifdef __GNUC__            
  647. static inline float Q_fabs(float x) {
  648.     float abs_x;
  649.     
  650.     asm("fabs %0,%1" : "=f" (abs_x) : "f" (x));
  651.     return abs_x;
  652. }
  653. #else
  654. #define Q_fabs __fabsf
  655. #endif
  656.  
  657. #else
  658. float Q_fabs( float f );
  659. float Q_rsqrt( float f );        // reciprocal square root
  660. #endif
  661.  
  662. #define SQRTFAST( x ) ( (x) * Q_rsqrt( x ) )
  663.  
  664. signed char ClampChar( int i );
  665. signed short ClampShort( int i );
  666.  
  667. float powf ( float x, int y );
  668.  
  669. // this isn't a real cheap function to call!
  670. int DirToByte( vec3_t dir );
  671. void ByteToDir( int b, vec3_t dir );
  672.  
  673. #if    1
  674.  
  675. #define minimum(x,y) ((x)<(y)?(x):(y))
  676. #define maximum(x,y) ((x)>(y)?(x):(y))
  677.  
  678. #define DotProduct(x,y)                    ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
  679. #define VectorSubtract(a,b,c)            ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
  680. #define VectorAdd(a,b,c)                ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
  681. #define VectorCopy(a,b)                    ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
  682. #define VectorCopy4(a,b)                ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
  683. #define    VectorScale(v, s, o)            ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
  684. #define    VectorMA(v, s, b, o)            ((o)[0]=(v)[0]+(b)[0]*(s),(o)[1]=(v)[1]+(b)[1]*(s),(o)[2]=(v)[2]+(b)[2]*(s))
  685. #define VectorInc(v)                    ((v)[0] += 1.0f,(v)[1] += 1.0f,(v)[2] +=1.0f)
  686. #define VectorDec(v)                    ((v)[0] -= 1.0f,(v)[1] -= 1.0f,(v)[2] -=1.0f)
  687. #define VectorInverseScaleVector(a,b,c)    ((c)[0]=(a)[0]/(b)[0],(c)[1]=(a)[1]/(b)[1],(c)[2]=(a)[2]/(b)[2])
  688. #define VectorScaleVectorAdd(c,a,b,o)    ((o)[0]=(c)[0]+((a)[0]*(b)[0]),(o)[1]=(c)[1]+((a)[1]*(b)[1]),(o)[2]=(c)[2]+((a)[2]*(b)[2]))
  689. #define VectorAdvance(a,s,b,c)            (((c)[0]=(a)[0] + s * ((b)[0] - (a)[0])),((c)[1]=(a)[1] + s * ((b)[1] - (a)[1])),((c)[2]=(a)[2] + s * ((b)[2] - (a)[2])))
  690. #define VectorAverage(a,b,c)            (((c)[0]=((a)[0]+(b)[0])*0.5f),((c)[1]=((a)[1]+(b)[1])*0.5f),((c)[2]=((a)[2]+(b)[2])*0.5f))
  691. #define VectorScaleVector(a,b,c)        (((c)[0]=(a)[0]*(b)[0]),((c)[1]=(a)[1]*(b)[1]),((c)[2]=(a)[2]*(b)[2]))
  692.  
  693. #else
  694.  
  695. #define DotProduct(x,y)            _DotProduct(x,y)
  696. #define VectorSubtract(a,b,c)    _VectorSubtract(a,b,c)
  697. #define VectorAdd(a,b,c)        _VectorAdd(a,b,c)
  698. #define VectorCopy(a,b)            _VectorCopy(a,b)
  699. #define    VectorScale(v, s, o)    _VectorScale(v,s,o)
  700. #define    VectorMA(v, s, b, o)    _VectorMA(v,s,b,o)
  701.  
  702. #endif
  703.  
  704. #ifdef __LCC__
  705. #ifdef VectorCopy
  706. #undef VectorCopy
  707. // this is a little hack to get more efficient copies in our interpreter
  708. typedef struct {
  709.     float    v[3];
  710. } vec3struct_t;
  711. #define VectorCopy(a,b)    (*(vec3struct_t *)b=*(vec3struct_t *)a)
  712. #define ID_INLINE static
  713. #endif
  714. #endif
  715.  
  716. #define VectorClear(a)            ((a)[0]=(a)[1]=(a)[2]=0)
  717. #define VectorNegate(a,b)        ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2])
  718. #define VectorSet(v, x, y, z)    ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z))
  719. #define VectorSet5(v,x,y,z,a,b)    ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z), (v)[3]=(a), (v)[4]=(b))
  720. #define Vector4Copy(a,b)        ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
  721.  
  722. #define    SnapVector(v) {v[0]=((int)(v[0]));v[1]=((int)(v[1]));v[2]=((int)(v[2]));}
  723. // just in case you do't want to use the macros
  724. vec_t _DotProduct( const vec3_t v1, const vec3_t v2 );
  725. void _VectorSubtract( const vec3_t veca, const vec3_t vecb, vec3_t out );
  726. void _VectorAdd( const vec3_t veca, const vec3_t vecb, vec3_t out );
  727. void _VectorCopy( const vec3_t in, vec3_t out );
  728. void _VectorScale( const vec3_t in, float scale, vec3_t out );
  729. void _VectorMA( const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc );
  730.  
  731. unsigned ColorBytes3 (float r, float g, float b);
  732. unsigned ColorBytes4 (float r, float g, float b, float a);
  733.  
  734. float NormalizeColor( const vec3_t in, vec3_t out );
  735.  
  736. float RadiusFromBounds( const vec3_t mins, const vec3_t maxs );
  737. void ClearBounds( vec3_t mins, vec3_t maxs );
  738. void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs );
  739.  
  740. #ifndef __LCC__
  741. static ID_INLINE int VectorCompare( const vec3_t v1, const vec3_t v2 ) {
  742.     if (v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2]) {
  743.         return 0;
  744.     }            
  745.     return 1;
  746. }
  747.  
  748. static ID_INLINE vec_t VectorLength( const vec3_t v ) {
  749.     return (vec_t)sqrt (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
  750. }
  751.  
  752. static ID_INLINE vec_t VectorLengthSquared( const vec3_t v ) {
  753.     return (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
  754. }
  755.  
  756. static ID_INLINE vec_t Distance( const vec3_t p1, const vec3_t p2 ) {
  757.     vec3_t    v;
  758.  
  759.     VectorSubtract (p2, p1, v);
  760.     return VectorLength( v );
  761. }
  762.  
  763. static ID_INLINE vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 ) {
  764.     vec3_t    v;
  765.  
  766.     VectorSubtract (p2, p1, v);
  767.     return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
  768. }
  769.  
  770. // fast vector normalize routine that does not check to make sure
  771. // that length != 0, nor does it return length, uses rsqrt approximation
  772. static ID_INLINE void VectorNormalizeFast( vec3_t v )
  773. {
  774.     float ilength;
  775.  
  776.     ilength = Q_rsqrt( DotProduct( v, v ) );
  777.  
  778.     v[0] *= ilength;
  779.     v[1] *= ilength;
  780.     v[2] *= ilength;
  781. }
  782.  
  783. static ID_INLINE void VectorInverse( vec3_t v ){
  784.     v[0] = -v[0];
  785.     v[1] = -v[1];
  786.     v[2] = -v[2];
  787. }
  788.  
  789. static ID_INLINE void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ) {
  790.     cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
  791.     cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
  792.     cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
  793. }
  794.  
  795. #else
  796. int VectorCompare( const vec3_t v1, const vec3_t v2 );
  797.  
  798. vec_t VectorLength( const vec3_t v );
  799.  
  800. vec_t VectorLengthSquared( const vec3_t v );
  801.  
  802. vec_t Distance( const vec3_t p1, const vec3_t p2 );
  803.  
  804. vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 );
  805.  
  806. void VectorNormalizeFast( vec3_t v );
  807.  
  808. void VectorInverse( vec3_t v );
  809.  
  810. void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross );
  811.  
  812. #endif
  813.  
  814. vec_t VectorNormalize (vec3_t v);        // returns vector length
  815. vec_t VectorNormalize2( const vec3_t v, vec3_t out );
  816. void Vector4Scale( const vec4_t in, vec_t scale, vec4_t out );
  817. void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out );
  818.  
  819. #ifndef __LCC__
  820. #ifndef    __linux__
  821.  
  822. static ID_INLINE int VectorToInt(vec3_t vec)
  823. {
  824.     int            tmp, retval;
  825.  
  826.     _asm
  827.     {
  828.         push    edx
  829.         mov        edx, [vec]
  830.         fld        dword ptr[edx + 0]
  831.         fld        dword ptr[edx + 4]
  832.         fld        dword ptr[edx + 8]
  833.  
  834.         mov        eax, 0xff00
  835.  
  836.         fistp    tmp       
  837.         mov        al, byte ptr [tmp]
  838.         shl        eax, 16
  839.         
  840.         fistp    tmp
  841.         mov        ah, byte ptr [tmp]
  842.  
  843.         fistp    tmp
  844.         mov        al, byte ptr [tmp]
  845.  
  846.         mov        [retval], eax
  847.         pop        edx
  848.     }
  849.     return(retval);
  850. }
  851.  
  852. static ID_INLINE int qftol( float f ) 
  853. {
  854.     int        temp;
  855.  
  856.     _asm
  857.     {
  858.         fld f
  859.         fistp temp
  860.         mov eax, temp
  861.     }
  862.     return(temp);
  863. }
  864.  
  865. #endif // __linux__
  866. #endif
  867.  
  868.  
  869. qboolean Q_TestRaySphere ( vec3_t origin, float radius, const vec3_t start, const vec3_t end );
  870.  
  871. int Q_log2(int val);
  872.  
  873. float Q_acos(float c);
  874. float Q_asin(float c);
  875.  
  876. int        Q_rand( int *seed );
  877. float    Q_random( int *seed );
  878. float    Q_crandom( int *seed );
  879.  
  880. #define random()    ((rand () & 0x7fff) / ((float)0x7fff))
  881. #define crandom()    (2.0 * (random() - 0.5))
  882.  
  883. void vectoangles( const vec3_t value1, vec3_t angles);
  884. void AnglesToAxis( const vec3_t angles, vec3_t axis[3] );
  885.  
  886. void AxisClear( vec3_t axis[3] );
  887. void AxisCopy( vec3_t in[3], vec3_t out[3] );
  888.  
  889. void SetPlaneSignbits( struct cplane_s *out );
  890. int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct cplane_s *plane);
  891.  
  892. double fmod( double x, double y );
  893. float    AngleMod(float a);
  894. float    LerpAngle (float from, float to, float frac);
  895. void    LerpVector ( vec3_t from, vec3_t to, float lerp, vec3_t out );
  896. float    AngleSubtract( float a1, float a2 );
  897. void    AnglesSubtract( vec3_t v1, vec3_t v2, vec3_t v3 );
  898.  
  899. float AngleNormalize360 ( float angle );
  900. float AngleNormalize180 ( float angle );
  901. float AngleDelta ( float angle1, float angle2 );
  902.  
  903. qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c );
  904. void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal );
  905. void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
  906. void RotateAroundDirection( vec3_t axis[3], float yaw );
  907. void MakeNormalVectors( const vec3_t forward, vec3_t right, vec3_t up );
  908. // perpendicular vector could be replaced by this
  909.  
  910. //int    PlaneTypeForNormal (vec3_t normal);
  911.  
  912. void MatrixMultiply(float in1[3][3], float in2[3][3], float out[3][3]);
  913. void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
  914. void PerpendicularVector( vec3_t dst, const vec3_t src );
  915. void NormalToLatLong( const vec3_t normal, byte bytes[2] );
  916.  
  917.  
  918. //=============================================
  919.  
  920. float Com_Clampf( float min, float max, float value );
  921. int Com_Clamp( int min, int max, int value );
  922.  
  923. char    *COM_SkipPath( char *pathname );
  924. void    COM_StripExtension( const char *in, char *out );
  925. void    COM_DefaultExtension( char *path, int maxSize, const char *extension );
  926.  
  927. void    COM_BeginParseSession( const char *name );
  928. int        COM_GetCurrentParseLine( void );
  929. const char    *SkipWhitespace( const char *data, qboolean *hasNewLines );
  930. char    *COM_Parse( const char **data_p );
  931. char    *COM_ParseExt( const char **data_p, qboolean allowLineBreak );
  932. int        COM_Compress( char *data_p );
  933. void    COM_ParseError( char *format, ... );
  934. void    COM_ParseWarning( char *format, ... );
  935. //int        COM_ParseInfos( char *buf, int max, char infos[][MAX_INFO_STRING] );
  936.  
  937. #define MAX_TOKENLENGTH        1024
  938.  
  939. #ifndef TT_STRING
  940. //token types
  941. #define TT_STRING                    1            // string
  942. #define TT_LITERAL                    2            // literal
  943. #define TT_NUMBER                    3            // number
  944. #define TT_NAME                        4            // name
  945. #define TT_PUNCTUATION                5            // punctuation
  946. #endif
  947.  
  948. typedef struct pc_token_s
  949. {
  950.     int type;
  951.     int subtype;
  952.     int intvalue;
  953.     float floatvalue;
  954.     char string[MAX_TOKENLENGTH];
  955. } pc_token_t;
  956.  
  957. // data is an in/out parm, returns a parsed out token
  958.  
  959. void    COM_MatchToken( const char**buf_p, char *match );
  960.  
  961. void SkipBracedSection (const char **program);
  962. void SkipRestOfLine ( const char **data );
  963.  
  964. void Parse1DMatrix (const char **buf_p, int x, float *m);
  965. void Parse2DMatrix (const char **buf_p, int y, int x, float *m);
  966. void Parse3DMatrix (const char **buf_p, int z, int y, int x, float *m);
  967.  
  968. int    QDECL Com_sprintf (char *dest, int size, const char *fmt, ...);
  969.  
  970.  
  971. // mode parm for FS_FOpenFile
  972. typedef enum {
  973.     FS_READ,
  974.     FS_WRITE,
  975.     FS_APPEND,
  976.     FS_APPEND_SYNC,
  977.     FS_READ_TEXT,
  978.     FS_WRITE_TEXT,
  979.     FS_APPEND_TEXT,
  980.     FS_APPEND_SYNC_TEXT
  981. } fsMode_t;
  982.  
  983. typedef enum {
  984.     FS_SEEK_CUR,
  985.     FS_SEEK_END,
  986.     FS_SEEK_SET
  987. } fsOrigin_t;
  988.  
  989. //=============================================
  990.  
  991. int Q_isprint( int c );
  992. int Q_islower( int c );
  993. int Q_isupper( int c );
  994. int Q_isalpha( int c );
  995.  
  996. // portable case insensitive compare
  997. int        Q_stricmp (const char *s1, const char *s2);
  998. int        Q_strncmp (const char *s1, const char *s2, int n);
  999. int        Q_stricmpn (const char *s1, const char *s2, int n);
  1000. char    *Q_strlwr( char *s1 );
  1001. char    *Q_strupr( char *s1 );
  1002. char    *Q_strrchr( const char* string, int c );
  1003.  
  1004. // buffer size safe library replacements
  1005. void    Q_strncpyz( char *dest, const char *src, int destsize );
  1006. void    Q_strcat( char *dest, int size, const char *src );
  1007.  
  1008. // strlen that discounts Quake color sequences
  1009. int Q_PrintStrlen( const char *string );
  1010. // removes color sequences from string
  1011. char *Q_CleanStr( char *string );
  1012.  
  1013. //=============================================
  1014.  
  1015. // 64-bit integers for global rankings interface
  1016. // implemented as a struct for qvm compatibility
  1017. typedef struct
  1018. {
  1019.     byte    b0;
  1020.     byte    b1;
  1021.     byte    b2;
  1022.     byte    b3;
  1023.     byte    b4;
  1024.     byte    b5;
  1025.     byte    b6;
  1026.     byte    b7;
  1027. } qint64;
  1028.  
  1029. //=============================================
  1030. /*
  1031. short    BigShort(short l);
  1032. short    LittleShort(short l);
  1033. int        BigLong (int l);
  1034. int        LittleLong (int l);
  1035. qint64  BigLong64 (qint64 l);
  1036. qint64  LittleLong64 (qint64 l);
  1037. float    BigFloat (const float *l);
  1038. float    LittleFloat (const float *l);
  1039.  
  1040. void    Swap_Init (void);
  1041. */
  1042. char    * QDECL va(char *format, ...);
  1043.  
  1044. //=============================================
  1045.  
  1046. //
  1047. // key / value info strings
  1048. //
  1049. char *Info_ValueForKey( const char *s, const char *key );
  1050. void Info_RemoveKey( char *s, const char *key );
  1051. void Info_RemoveKey_big( char *s, const char *key );
  1052. void Info_SetValueForKey( char *s, const char *key, const char *value );
  1053. void Info_SetValueForKey_Big( char *s, const char *key, const char *value );
  1054. qboolean Info_Validate( const char *s );
  1055. void Info_NextPair( const char **s, char *key, char *value );
  1056.  
  1057. void    QDECL Com_Error( int level, const char *error, ... );
  1058. void    QDECL Com_Printf( const char *msg, ... );
  1059.  
  1060.  
  1061. /*
  1062. ==========================================================
  1063.  
  1064. CVARS (console variables)
  1065.  
  1066. Many variables can be used for cheating purposes, so when
  1067. cheats is zero, force all unspecified variables to their
  1068. default values.
  1069. ==========================================================
  1070. */
  1071.  
  1072. #define    CVAR_ARCHIVE        0x00000001        // set to cause it to be saved to vars.rc
  1073.                                             // used for system variables, not for player
  1074.                                             // specific configurations
  1075. #define    CVAR_USERINFO        0x00000002        // sent to server on connect or change
  1076. #define    CVAR_SERVERINFO        0x00000004        // sent in response to front end requests
  1077. #define    CVAR_SYSTEMINFO        0x00000008        // these cvars will be duplicated on all clients
  1078. #define    CVAR_INIT            0x00000010        // don't allow change from console at all,
  1079.                                             // but can be set from the command line
  1080. #define    CVAR_LATCH            0x00000020        // will only change when C code next does
  1081.                                             // a Cvar_Get(), so it can't be changed
  1082.                                             // without proper initialization.  modified
  1083.                                             // will be set, even though the value hasn't
  1084.                                             // changed yet
  1085. #define    CVAR_ROM            0x00000040        // display only, cannot be set by user at all (can be set by code)
  1086. #define    CVAR_USER_CREATED    0x00000080        // created by a set command
  1087. #define    CVAR_TEMP            0x00000100        // can be set even when cheats are disabled, but is not archived
  1088. #define CVAR_CHEAT            0x00000200        // can not be changed if cheats are disabled
  1089. #define CVAR_NORESTART        0x00000400        // do not clear when a cvar_restart is issued
  1090. #define CVAR_INTERNAL        0x00000800        // cvar won't be displayed, ever (for passwords and such)
  1091. #define    CVAR_PARENTAL        0x00001000        // lets cvar system know that parental stuff needs to be updated
  1092. #define CVAR_LOCK_RANGE        0x00002000        // enforces the mins / maxs
  1093.  
  1094. // nothing outside the Cvar_*() functions should modify these fields!
  1095. typedef struct cvar_s {
  1096.     char        *name;
  1097.     char        *string;
  1098.     char        *resetString;        // cvar_restart will reset to this value
  1099.     char        *latchedString;        // for CVAR_LATCH vars
  1100.     float        mMinValue, mMaxValue;
  1101.     int            flags;
  1102.     qboolean    modified;            // set each time the cvar is changed
  1103.     int            modificationCount;    // incremented each time the cvar is changed
  1104.     float        value;                // atof( string )
  1105.     int            integer;            // atoi( string )
  1106.     struct cvar_s *next;
  1107.     struct cvar_s *hashNext;
  1108. } cvar_t;
  1109.  
  1110. #define    MAX_CVAR_VALUE_STRING    256
  1111.  
  1112. typedef int    cvarHandle_t;
  1113.  
  1114. // the modules that run in the virtual machine can't access the cvar_t directly,
  1115. // so they must ask for structured updates
  1116. typedef struct {
  1117.     cvarHandle_t    handle;
  1118.     int            modificationCount;
  1119.     float        value;
  1120.     int            integer;
  1121.     char        string[MAX_CVAR_VALUE_STRING];
  1122. } vmCvar_t;
  1123.  
  1124. /*
  1125. ==============================================================
  1126.  
  1127. COLLISION DETECTION
  1128.  
  1129. ==============================================================
  1130. */
  1131.  
  1132. #include "surfaceflags.h"            // shared with the q3map utility
  1133.  
  1134. // plane types are used to speed some tests
  1135. // 0-2 are axial planes
  1136. #define    PLANE_X            0
  1137. #define    PLANE_Y            1
  1138. #define    PLANE_Z            2
  1139. #define    PLANE_NON_AXIAL    3
  1140.  
  1141.  
  1142. /*
  1143. =================
  1144. PlaneTypeForNormal
  1145. =================
  1146. */
  1147.  
  1148. #define PlaneTypeForNormal(x) (x[0] == 1.0 ? PLANE_X : (x[1] == 1.0 ? PLANE_Y : (x[2] == 1.0 ? PLANE_Z : PLANE_NON_AXIAL) ) )
  1149.  
  1150. // plane_t structure
  1151. // !!! if this is changed, it must be changed in asm code too !!!
  1152. typedef struct cplane_s {
  1153.     vec3_t    normal;
  1154.     float    dist;
  1155.     byte    type;            // for fast side tests: 0,1,2 = axial, 3 = nonaxial
  1156.     byte    signbits;        // signx + (signy<<1) + (signz<<2), used as lookup during collision
  1157.     byte    pad[2];
  1158. } cplane_t;
  1159. /*
  1160. Ghoul2 Insert Start
  1161. */
  1162. typedef struct
  1163. {
  1164.     float        mDistance;
  1165.     int            mEntityNum;
  1166.     int            mModelIndex;
  1167.     int            mPolyIndex;
  1168.     int            mSurfaceIndex;
  1169.     vec3_t        mCollisionPosition;
  1170.     vec3_t        mCollisionNormal;
  1171.     int            mFlags;
  1172.     int            mMaterial;
  1173.     int            mLocation;
  1174.     float        mBarycentricI; // two barycentic coodinates for the hit point
  1175.     float        mBarycentricJ; // K = 1-I-J
  1176. }CollisionRecord_t;
  1177.  
  1178. #define MAX_G2_COLLISIONS 16
  1179.  
  1180. typedef CollisionRecord_t G2Trace_t[MAX_G2_COLLISIONS];    // map that describes all of the parts of ghoul2 models that got hit
  1181.  
  1182. /*
  1183. Ghoul2 Insert End
  1184. */
  1185. // a trace is returned when a box is swept through the world
  1186. typedef struct {
  1187.     qboolean    allsolid;    // if true, plane is not valid
  1188.     qboolean    startsolid;    // if true, the initial point was in a solid area
  1189.     float        fraction;    // time completed, 1.0 = didn't hit anything
  1190.     vec3_t        endpos;        // final position
  1191.     cplane_t    plane;        // surface normal at impact, transformed to world space
  1192.     int            surfaceFlags;    // surface hit
  1193.     int            contents;    // contents on other side of surface hit
  1194.     int            entityNum;    // entity the contacted sirface is a part of
  1195. } trace_t;
  1196.  
  1197. // calling defines for the trace function
  1198. enum EG2_Collision
  1199. {
  1200.     G2_NOCOLLIDE,
  1201.     G2_COLLIDE,
  1202.     G2_RETURNONHIT
  1203. };
  1204.  
  1205. typedef enum 
  1206. {
  1207.     WF_BASEMODEL =                    (1<<0),
  1208.     WF_CLIENTONLY =                    (1<<1),
  1209.     WF_SERVERONLY =                    (1<<2),
  1210.     WF_NPC =                        (1<<3),
  1211.     WF_DM_SKELETON =                (1<<4),
  1212.  
  1213. } EWraithInstFlags;
  1214.  
  1215. // trace->entityNum can also be 0 to (MAX_GENTITIES-1)
  1216. // or ENTITYNUM_NONE, ENTITYNUM_WORLD
  1217.  
  1218.  
  1219. // markfragments are returned by CM_MarkFragments()
  1220. typedef struct 
  1221. {
  1222.     int        firstPoint;
  1223.     int        numPoints;
  1224.  
  1225. } markFragment_t;
  1226.  
  1227.  
  1228. typedef struct 
  1229. {
  1230.     vec3_t        origin;
  1231.     vec3_t        axis[3];
  1232.  
  1233. } orientation_t;
  1234.  
  1235. typedef struct 
  1236. {
  1237.     float        yawAngle;
  1238.     qboolean    yawing;
  1239.  
  1240.     float        pitchAngle;
  1241.     qboolean    pitching;
  1242.  
  1243.     int            anim;
  1244.     int            animTime;
  1245.  
  1246. } animInfo_t;
  1247.  
  1248. //=====================================================================
  1249.  
  1250.  
  1251. // in order from highest priority to lowest
  1252. // if none of the catchers are active, bound key strings will be executed
  1253. #define KEYCATCH_CONSOLE        0x0001
  1254. #define    KEYCATCH_UI                0x0002
  1255. #define    KEYCATCH_MESSAGE        0x0004
  1256. #define    KEYCATCH_CGAME            0x0008
  1257. #define KEYCATCH_NUMBERSONLY    0x0010
  1258.  
  1259. // sound channels
  1260. // channel 0 never willingly overrides
  1261. // other channels will allways override a playing sound on that channel
  1262. typedef enum {
  1263.     CHAN_AUTO,
  1264.     CHAN_LOCAL,        // menu sounds, etc
  1265.     CHAN_WEAPON,
  1266.     CHAN_VOICE,
  1267.     CHAN_ITEM,
  1268.     CHAN_BODY,
  1269.     CHAN_LOCAL_SOUND,    // chat messages, etc
  1270.     CHAN_ANNOUNCER,        // announcer voices, etc
  1271.     CHAN_AMBIENT,        //# ingame NPC weapons only, do not use in scripts!
  1272. } soundChannel_t;
  1273.  
  1274.  
  1275. /*
  1276. ========================================================================
  1277.  
  1278.   ELEMENTS COMMUNICATED ACROSS THE NET
  1279.  
  1280. ========================================================================
  1281. */
  1282.  
  1283. #define    ANGLE2SHORT(x)    ((int)((x)*65536/360) & 65535)
  1284. #define    SHORT2ANGLE(x)    ((x)*(360.0/65536))
  1285.  
  1286. #define    SNAPFLAG_RATE_DELAYED    1
  1287. #define    SNAPFLAG_NOT_ACTIVE        2    // snapshot used during connection and for zombies
  1288. #define SNAPFLAG_SERVERCOUNT    4    // toggled every map_restart so transitions can be detected
  1289.  
  1290. //
  1291. // per-level limits
  1292. //
  1293. #define    MAX_CLIENTS            64        // absolute limit
  1294. #define MAX_LOCATIONS        64
  1295. #define MAX_TERRAINS        32
  1296. #define MAX_LADDERS            64
  1297.  
  1298. #define MAX_INSTANCE_TYPES        16
  1299.  
  1300. #define    GENTITYNUM_BITS            10        // don't need to send any more
  1301. #define    MAX_GENTITIES            (1<<GENTITYNUM_BITS)
  1302.  
  1303. // entitynums are communicated with GENTITY_BITS, so any reserved
  1304. // values thatare going to be communcated over the net need to
  1305. // also be in this range
  1306. #define    ENTITYNUM_NONE            (MAX_GENTITIES-1)
  1307. #define    ENTITYNUM_WORLD            (MAX_GENTITIES-2)
  1308. #define    ENTITYNUM_MAX_NORMAL    (MAX_GENTITIES-2)
  1309.  
  1310.  
  1311. // these are also in be_aas_def.h - argh (rjr)
  1312. #define    MAX_MODELS                256        // these are sent over the net as 8 bits
  1313. #define    MAX_SOUNDS                256        // so they cannot be blindly increased
  1314. #define MAX_AMBIENT_SOUNDSETS    64
  1315. #define MAX_FX                    64        // max effects strings, I'm hoping that 64 will be plenty
  1316. #define MAX_SUB_BSP                32
  1317. #define MAX_ICONS                32
  1318. #define    MAX_CHARSKINS            64        // character skins
  1319. #define    MAX_HUDICONS            16        // icons on hud
  1320.  
  1321. #define    MAX_CONFIGSTRINGS    1400
  1322.  
  1323. // these are the only configstrings that the system reserves, all the
  1324. // other ones are strictly for servergame to clientgame communication
  1325. #define    CS_SERVERINFO        0        // an info string with all the serverinfo cvars
  1326. #define    CS_SYSTEMINFO        1        // an info string for server system to client system configuration (timescale, etc)
  1327. #define CS_PLAYERS            2        // info string for player user info
  1328. #define CS_CUSTOM            (CS_PLAYERS + MAX_CLIENTS )
  1329.  
  1330. #define    RESERVED_CONFIGSTRINGS    2    // game can't modify below this, only the system can
  1331.  
  1332. #define    MAX_GAMESTATE_CHARS    16000
  1333. typedef struct {
  1334.     int            stringOffsets[MAX_CONFIGSTRINGS];
  1335.     char        stringData[MAX_GAMESTATE_CHARS];
  1336.     int            dataCount;
  1337. } gameState_t;
  1338.  
  1339. //=========================================================
  1340.  
  1341. // bit field limits
  1342. #define    MAX_STATS                16
  1343. #define    MAX_PERSISTANT            16
  1344. #define    MAX_AMMO                16
  1345. #define    MAX_WEAPONS                32
  1346. #define MAX_GAMETYPE_ITEMS        5
  1347.  
  1348. #define    MAX_PS_EVENTS            4
  1349.  
  1350. #define PS_PMOVEFRAMECOUNTBITS    6
  1351.  
  1352. typedef enum
  1353. {
  1354.     ATTACK_NORMAL,
  1355.     ATTACK_ALTERNATE,
  1356.     ATTACK_MAX
  1357.  
  1358. } attackType_t;
  1359.  
  1360. // playerState_t is the information needed by both the client and server
  1361. // to predict player motion and actions
  1362. // nothing outside of pmove should modify these, or some degree of prediction error
  1363. // will occur
  1364.  
  1365. // you can't add anything to this without modifying the code in msg.c
  1366.  
  1367. // playerState_t is a full superset of entityState_t as it is used by players,
  1368. // so if a playerState_t is transmitted, the entityState_t can be fully derived
  1369. // from it.
  1370.  
  1371. typedef struct playerState_s 
  1372. {
  1373.     int            commandTime;    // cmd->serverTime of last executed command
  1374.     int            pm_type;
  1375.     int            bobCycle;        // for view bobbing and footstep generation
  1376.     int            pm_flags;        // ducked, etc
  1377.     int            pm_debounce;    // debounce buttons
  1378.     int            pm_time;
  1379.  
  1380.     vec3_t        origin;
  1381.     vec3_t        velocity;
  1382.  
  1383.     int            weaponTime;
  1384.     int            weaponFireBurstCount;
  1385.     int            weaponAnimId;
  1386.     int            weaponAnimIdChoice;
  1387.     int            weaponAnimTime;
  1388.     int            weaponCallbackTime;
  1389.     int            weaponCallbackStep;
  1390.  
  1391.     int            gravity;
  1392.     int            speed;
  1393.     int            delta_angles[3];                // add to command angles to get view direction
  1394.                                                 // changed by spawns, rotating objects, and teleporters
  1395.     int            groundEntityNum;                // ENTITYNUM_NONE = in air
  1396.                                                 
  1397.     int            legsAnim;                        // mask off ANIM_TOGGLEBIT
  1398.                                                 
  1399.     int            torsoTimer;                        // don't change low priority animations until this runs out
  1400.     int            torsoAnim;                        // mask off ANIM_TOGGLEBIT
  1401.                                                 
  1402.     int            movementDir;                    // a number 0 to 7 that represents the reletive angle
  1403.                                                 // of movement to the view angle (axial and diagonals)
  1404.                                                 // when at rest, the value will remain unchanged
  1405.                                                 // used to twist the legs during strafing
  1406.                                                 
  1407.     int            eFlags;                            // copied to entityState_t->eFlags
  1408.                                                 
  1409.     int            eventSequence;                    // pmove generated events
  1410.     int            events[MAX_PS_EVENTS];            
  1411.     int            eventParms[MAX_PS_EVENTS];        
  1412.                                                 
  1413.     int            externalEvent;                    // events set on player from another source
  1414.     int            externalEventParm;                
  1415.     int            externalEventTime;                
  1416.                                                 
  1417.     int            clientNum;                        // ranges from 0 to MAX_CLIENTS-1
  1418.     int            weapon;                            // copied to entityState_t->weapon
  1419.     int            weaponstate;                    
  1420.                                                 
  1421.     vec3_t        viewangles;                        // for fixed views
  1422.     int            viewheight;                        
  1423.                                                 
  1424.     // damage feedback                            
  1425.     int            damageEvent;                    // when it changes, latch the other parms
  1426.     int            damageYaw;                        
  1427.     int            damagePitch;                    
  1428.     int            damageCount;                    
  1429.                                                 
  1430.     int            painTime;                        // used for both game and client side to process the pain twitch - NOT sent across the network
  1431.     int            painDirection;                    // NOT sent across the network
  1432.                                         
  1433.     int            stats[MAX_STATS];                
  1434.     int            persistant[MAX_PERSISTANT];        // stats that aren't cleared on death
  1435.     int            ammo[MAX_AMMO];
  1436.     int            clip[ATTACK_MAX][MAX_WEAPONS];
  1437.     int            firemode[MAX_WEAPONS];
  1438.  
  1439.     int            generic1;
  1440.     int            loopSound;
  1441.  
  1442.     // Incaccuracy values for firing
  1443.     int            inaccuracy;
  1444.     int            inaccuracyTime;
  1445.     int            kickPitch;
  1446.  
  1447.     // not communicated over the net at all
  1448.     int            ping;                            // server to game info for scoreboard
  1449.     int            pmove_framecount;                // FIXME: don't transmit over the network
  1450.     int            jumppad_frame;
  1451.     int            entityEventSequence;
  1452.     vec3_t        pvsOrigin;                        // view origin used to calculate PVS (also the lean origin)
  1453.                                                 // THIS VARIABLE MUST AT LEAST BE THE PLAYERS ORIGIN ALL OF THE 
  1454.                                                 // TIME OR THE PVS CALCULATIONS WILL NOT WORK.
  1455.  
  1456.     // Zooming
  1457.     int            zoomTime;
  1458.     int            zoomFov;
  1459.  
  1460.     // LAdders
  1461.     int            ladder;
  1462.     int            leanTime;
  1463.  
  1464.     // Timers 
  1465.     int            grenadeTimer;
  1466.     int            respawnTimer;
  1467.  
  1468. } playerState_t;
  1469.  
  1470.  
  1471. typedef enum 
  1472. {
  1473.     TEAM_FREE,
  1474.     TEAM_RED,
  1475.     TEAM_BLUE,
  1476.     TEAM_SPECTATOR,
  1477.  
  1478.     TEAM_NUM_TEAMS
  1479.  
  1480. } team_t;
  1481.  
  1482. //====================================================================
  1483.  
  1484.  
  1485. //
  1486. // usercmd_t->button bits, many of which are generated by the client system,
  1487. // so they aren't game/cgame only definitions
  1488. //
  1489. #define    BUTTON_ATTACK        (1<<0)
  1490. #define    BUTTON_TALK            (1<<1)            // displays talk balloon and disables actions    
  1491. #define BUTTON_GOGGLES        (1<<2)            // turns nv or therm goggles on/off
  1492. #define BUTTON_LEAN            (1<<3)            // lean modifier, when held strafe left and right will lean
  1493. #define    BUTTON_WALKING        (1<<4)            // walking can't just be infered from MOVE_RUN
  1494.                                             // because a key pressed late in the frame will
  1495.                                             // only generate a small move value for that frame
  1496.                                             // walking will use different animations and
  1497.                                             // won't generate footsteps
  1498. #define    BUTTON_USE            (1<<5)            // the ol' use key returns!
  1499. #define    BUTTON_RELOAD        (1<<6)            // reloads current weapon
  1500. #define BUTTON_ALT_ATTACK    (1<<7)
  1501. #define    BUTTON_ANY            (1<<8)            // any key whatsoever
  1502. #define BUTTON_ZOOMIN        (1<<9)
  1503. #define BUTTON_ZOOMOUT        (1<<10)
  1504. #define BUTTON_FIREMODE        (1<<11)
  1505.  
  1506. #define BUTTON_LEAN_RIGHT    (1<<12)
  1507. #define BUTTON_LEAN_LEFT    (1<<13)
  1508.  
  1509.  
  1510. // usercmd_t is sent to the server each client frame
  1511. typedef struct usercmd_s 
  1512. {
  1513.     int                serverTime;
  1514.     int                angles[3];
  1515.     int             buttons;
  1516.     byte            weapon;
  1517.     signed char        forwardmove;
  1518.     signed char        rightmove;
  1519.     signed char        upmove;
  1520.  
  1521. } usercmd_t;
  1522.  
  1523. //===================================================================
  1524.  
  1525. // if entityState->solid == SOLID_BMODEL, modelindex is an inline model number
  1526. #define    SOLID_BMODEL    0xffffff
  1527.  
  1528. typedef enum {
  1529.     TR_STATIONARY,
  1530.     TR_INTERPOLATE,                // non-parametric, but interpolate between snapshots
  1531.     TR_LINEAR,
  1532.     TR_LINEAR_STOP,
  1533.     TR_SINE,                    // value = base + sin( time / duration ) * delta
  1534.     TR_GRAVITY,
  1535.     TR_HEAVYGRAVITY,
  1536.     TR_LIGHTGRAVITY
  1537. } trType_t;
  1538.  
  1539. typedef struct {
  1540.     trType_t    trType;
  1541.     int        trTime;
  1542.     int        trDuration;            // if non 0, trTime + trDuration = stop time
  1543.     vec3_t    trBase;
  1544.     vec3_t    trDelta;            // velocity, etc
  1545. } trajectory_t;
  1546.  
  1547. // entityState_t is the information conveyed from the server
  1548. // in an update message about entities that the client will
  1549. // need to render in some way
  1550. // Different eTypes may use the information in different ways
  1551. // The messages are delta compressed, so it doesn't really matter if
  1552. // the structure size is fairly large
  1553.  
  1554. typedef struct entityState_s 
  1555. {
  1556.     int                number;            // entity index
  1557.     int                eType;            // entityType_t
  1558.     int                eFlags;
  1559.  
  1560.     trajectory_t    pos;            // for calculating position
  1561.     trajectory_t    apos;            // for calculating angles
  1562.  
  1563.     int                time;
  1564.     int                time2;
  1565.                     
  1566.     vec3_t            origin;
  1567.     vec3_t            origin2;
  1568.                     
  1569.     vec3_t            angles;
  1570.     vec3_t            angles2;
  1571.                     
  1572.     int                otherEntityNum;    // shotgun sources, etc
  1573.     int                otherEntityNum2;
  1574.                     
  1575.     int                groundEntityNum;    // -1 = in air
  1576.                     
  1577.     int                loopSound;        // constantly loop this sound
  1578.     int                mSoundSet;
  1579.                                         
  1580.     int                modelindex;
  1581.     int                modelindex2;
  1582.     int                clientNum;        // 0 to (MAX_CLIENTS - 1), for players and corpses
  1583.     int                frame;
  1584.                     
  1585.     int                solid;            // for client side prediction, trap_linkentity sets this properly
  1586.                     
  1587.     int                event;            // impulse events -- muzzle flashes, footsteps, etc
  1588.     int                eventParm;
  1589.  
  1590.     int                generic1;
  1591.  
  1592.     // for players
  1593.     // these fields are only transmitted for client entities!!!!!
  1594.     int                gametypeitems;    // bit flags indicating which items are carried
  1595.     int                weapon;            // determines weapon and flash model, etc
  1596.     int                legsAnim;        // mask off ANIM_TOGGLEBIT
  1597.     int                torsoAnim;        // mask off ANIM_TOGGLEBIT
  1598.     int                torsoTimer;        // time the animation will play for
  1599.     int                leanOffset;        // Lean direction
  1600. } entityState_t;
  1601.  
  1602.  
  1603.  
  1604. typedef enum {
  1605.     CA_UNINITIALIZED,
  1606.     CA_DISCONNECTED,     // not talking to a server
  1607.     CA_AUTHORIZING,        // not used any more, was checking cd key 
  1608.     CA_CONNECTING,        // sending request packets to the server
  1609.     CA_CHALLENGING,        // sending challenge packets to the server
  1610.     CA_CONNECTED,        // netchan_t established, getting gamestate
  1611.     CA_LOADING,            // only during cgame initialization, never during main loop
  1612.     CA_PRIMED,            // got gamestate, waiting for first frame
  1613.     CA_ACTIVE,            // game views should be displayed
  1614.     CA_CINEMATIC        // playing a cinematic or a static pic, not connected to a server
  1615. } connstate_t;
  1616.  
  1617. #define Square(x) ((x)*(x))
  1618.  
  1619. // real time
  1620. //=============================================
  1621.  
  1622.  
  1623. typedef struct qtime_s {
  1624.     int tm_sec;     /* seconds after the minute - [0,59] */
  1625.     int tm_min;     /* minutes after the hour - [0,59] */
  1626.     int tm_hour;    /* hours since midnight - [0,23] */
  1627.     int tm_mday;    /* day of the month - [1,31] */
  1628.     int tm_mon;     /* months since January - [0,11] */
  1629.     int tm_year;    /* years since 1900 */
  1630.     int tm_wday;    /* days since Sunday - [0,6] */
  1631.     int tm_yday;    /* days since January 1 - [0,365] */
  1632.     int tm_isdst;   /* daylight savings time flag */
  1633. } qtime_t;
  1634.  
  1635.  
  1636. // server browser sources
  1637. #define AS_LOCAL            0
  1638. #define AS_GLOBAL            1
  1639. #define AS_FAVORITES        2
  1640.  
  1641.  
  1642. // cinematic states
  1643. typedef enum {
  1644.     FMV_IDLE,
  1645.     FMV_PLAY,        // play
  1646.     FMV_EOF,        // all other conditions, i.e. stop/EOF/abort
  1647.     FMV_ID_BLT,
  1648.     FMV_ID_IDLE,
  1649.     FMV_LOOPED,
  1650.     FMV_ID_WAIT
  1651. } e_status;
  1652.  
  1653.  
  1654. #define    MAX_GLOBAL_SERVERS            2048
  1655. #define    MAX_OTHER_SERVERS            128
  1656. #define MAX_PINGREQUESTS            32
  1657. #define MAX_SERVERSTATUSREQUESTS    16
  1658.  
  1659. #define SAY_ALL        0
  1660. #define SAY_TEAM    1
  1661. #define SAY_TELL    2
  1662.  
  1663. #define CDKEY_LEN 16
  1664. #define CDCHKSUM_LEN 2
  1665.  
  1666. void Rand_Init(int seed);
  1667. float flrand(float min, float max);
  1668. int irand(int min, int max);
  1669. int Q_irand(int value1, int value2);
  1670.  
  1671. #ifdef __cplusplus
  1672.     #define RAND_TABLE_SIZE        1024
  1673.  
  1674.     extern    int        randIndex;
  1675.     extern    float    randTable[RAND_TABLE_SIZE];
  1676.  
  1677.     inline float flrand(void) { return(randTable[randIndex++ & (RAND_TABLE_SIZE - 1)]); }
  1678. #endif
  1679.  
  1680.  
  1681. /*
  1682. Ghoul2 Insert Start
  1683. */
  1684.  
  1685. typedef struct {
  1686.     float        matrix[3][4];
  1687. } mdxaBone_t;
  1688.  
  1689. // For ghoul2 axis use
  1690.  
  1691. typedef enum Eorientations
  1692. {
  1693.     ORIGIN = 0, 
  1694.     POSITIVE_X,
  1695.     POSITIVE_Z,
  1696.     POSITIVE_Y,
  1697.     NEGATIVE_X,
  1698.     NEGATIVE_Z,
  1699.     NEGATIVE_Y
  1700. };
  1701. /*
  1702. Ghoul2 Insert End
  1703. */
  1704.  
  1705.  
  1706. // define the new memory tags for the zone, used by all modules now
  1707. //
  1708. #define TAGDEF(blah) TAG_ ## blah
  1709. typedef enum {
  1710.     #include "../qcommon/tags.h"
  1711. } memtag_t;
  1712.  
  1713. typedef struct 
  1714. {
  1715.     int        isValid;    
  1716.     void    *ghoul2;
  1717.     int        modelNum;
  1718.     int        boltNum;
  1719.     vec3_t    angles;
  1720.     vec3_t    origin;
  1721.     vec3_t    scale;
  1722.     vec3_t    dir;
  1723.     vec3_t    forward;
  1724.  
  1725. } CFxBoltInterface;
  1726.  
  1727.  
  1728. /*
  1729. ========================================================================
  1730.  
  1731. Version Download
  1732.  
  1733. ========================================================================
  1734. */
  1735.  
  1736. #define VD_IGNORE            -3
  1737. #define VD_CANCEL            -2
  1738. #define VD_BROWSER_DOWNLOAD    -1
  1739.  
  1740.  
  1741. /*
  1742. ========================================================================
  1743.  
  1744. Generic string hash table
  1745.  
  1746. ========================================================================
  1747. */
  1748. #define KEYWORDHASH_SIZE    512
  1749.  
  1750. typedef struct keywordHash_s
  1751. {
  1752.     char                    *name;        // Name of keyword
  1753.     struct keywordHash_s    *next;        // Used for collisions
  1754.  
  1755. } keywordHash_t;
  1756.  
  1757. int                KeywordHash_Key        ( char *keyword );
  1758. void            KeywordHash_Add        ( keywordHash_t *table[], keywordHash_t *key );
  1759. keywordHash_t*    KeywordHash_Find    ( keywordHash_t *table[], char *keyword );
  1760.  
  1761. /*
  1762. ========================================================================
  1763.  
  1764. String ID Tables
  1765.  
  1766. ========================================================================
  1767. */
  1768. #define ENUM2STRING(arg)   #arg,arg
  1769. typedef struct stringID_table_s
  1770. {
  1771.     char    *name;
  1772.     int        id;
  1773. } stringID_table_t;
  1774.  
  1775. int GetIDForString ( stringID_table_t *table, const char *string );
  1776. const char *GetStringForID( stringID_table_t *table, int id );
  1777.  
  1778.  
  1779. // stuff to help out during development process, force reloading/uncacheing of certain filetypes...
  1780. //
  1781. typedef enum
  1782. {
  1783.     eForceReload_NOTHING,
  1784. //    eForceReload_BSP,    // not used in MP codebase
  1785.     eForceReload_MODELS,
  1786.     eForceReload_ALL
  1787.  
  1788. } ForceReload_e;
  1789.  
  1790.  
  1791. #endif    // __Q_SHARED_H
  1792.